new Handle:g_ChatStuck = INVALID_HANDLE
new Handle:g_ChatHide = INVALID_HANDLE
new Handle:g_ChatKill = INVALID_HANDLE
new Handle:g_ChatCamera = INVALID_HANDLE
new Handle:g_ChatRespawn = INVALID_HANDLE
new Handle:g_ChatConsole = INVALID_HANDLE
new Handle:g_ChatOverflow = INVALID_HANDLE
new Handle:g_ChatRetry = INVALID_HANDLE
new Handle:g_ChatCommands = INVALID_HANDLE
new Handle:g_Stuck = INVALID_HANDLE
new Handle:g_Explode = INVALID_HANDLE
new Handle:g_Kill = INVALID_HANDLE
new bool:g_Return = false
new bool:g_Check = false

//----------------------------------//
// Here we capture the chat message //
//----------------------------------//
public Action:Say_Command(client, const String:command[], argc)
{
	if (Debug)
		PrintToChat(client, "[SYN] Chat message Triggerd")

	// saving the message to a string (Cmd) 
	// to compare it later
	decl String:Cmd[192]
	decl String:Cmd2[2]
	GetCmdArgString(Cmd, sizeof(Cmd))
	ReplaceString(Cmd, sizeof(Cmd), "\"", "")
	Format(Cmd2, sizeof(Cmd2), "%s", Cmd)

	if (Debug)
		PrintToChat(client, "[SYN] Chat message Triggerd: %s", Cmd)

	// If message contains "!" then we go and compare it 
	// Why we do this? Because it costs less CPU
	if (StrEqual(Cmd2, "!", false) || StrEqual(Cmd2, "/", false))
	{
		// If message contains "!" then we are going to compare
		if (StrEqual(Cmd2, "!", false))
		{
			if (Debug)
				PrintToChat(client, "[SYN] We have found '!'")
			g_Check = true
			g_Return = false
		}
		// If message contains "/" then we hide it from chat
		if (StrEqual(Cmd2, "/", false))
		{
			if (Debug)
				PrintToChat(client, "[SYN] We have found '/'")
			g_Return = true
			g_Check = true
		}
		else
		{
			if (Debug)
				PrintToChat(client, "[SYN] We have not found '/'")
			g_Return = false
		}
	}
	else
	{
		// We need to write the message into chat again, otherwise it will not be displayed
		if (Debug)
			PrintToChat(client, "[SYN] We have not found '!' nor '/'")
		g_Check = false
		g_Return = false
	}

	//----------------------------------------------------//
	// Here we are starting to compare with chat triggers //
	//----------------------------------------------------//
	if (g_Check && GetConVarInt(g_ChatCommands))
	{
		// Stuck Command
		if (GetConVarInt(g_ChatStuck))
		{
			if(StrEqual(Cmd, "!stuck", false) || StrEqual(Cmd, "/stuck", false))
			{
				if (GetConVarInt(g_Stuck))
				{
					FakeClientCommandEx(client, "stuck")
				}
				else
				{
					PrintToChat(client,"\x01\x04[SM] %T", "StuckDisabled", LANG_SERVER)
				}
			}
		}
		
		// Kill Command
		if (GetConVarInt(g_ChatKill))
		{
			if(StrEqual(Cmd, "!kill", false) || StrEqual(Cmd, "/kill", false))
			{
				ForcePlayerSuicide(client)
			}
		}
		
		// Goto disable Command
		if (GetConVarInt(g_Goto))
		{
			if(StrEqual(Cmd, "!gotodisable", false) || StrEqual(Cmd, "/gotodisable", false) || StrEqual(Cmd, "!nogoto", false) || StrEqual(Cmd, "/nogoto", false))
			{
				if(AGoto[client]){
					PrintToChat(client,"\x01\x04[SM] Nobody can teleport to you now.")
					AGoto[client] = false
				}
				else if(!AGoto[client]){
					PrintToChat(client,"\x01\x04[SM] Player can teleport to you now.")
					AGoto[client] = true
				}
			}
		}
		
		// CameraMode Command
		if (GetConVarInt(g_ChatCamera))
		{
			if(StrEqual(Cmd, "!camera", false) || StrEqual(Cmd, "/camera", false))
			{
				ClientCommand(client, "cameramode")
				PrintToChat(client,"\x01\x04[SM] %T", "CameraMode", LANG_SERVER)
			}
		}
		
		// Help Command
		if (GetConVarInt(g_Info))
		{
			if(StrEqual(Cmd, "!help", false) || StrEqual(Cmd, "/help", false) || StrEqual(Cmd, "!info", false) || StrEqual(Cmd, "/info", false))
			{
				CreateTimer(0.1, DO_InfoPlayer, client)
			}
		}
		
		// Respawn Command
		if (GetConVarInt(g_ChatRespawn) && GetConVarInt(g_SpawnPlayer))
		{
			if(StrEqual(Cmd, "!respawn", false) || StrEqual(Cmd, "/respawn", false) || StrEqual(Cmd, "/spawn", false) || StrEqual(Cmd, "!spawn", false))
			{
				if (Synergy && PlayerDead(client) && !IsRespawn[client])
				{
					IsRespawn[client] = true
					SpawnPlayer(client)
					PrintToChat(client,"\x01\x04[SM] You are being spawned...")
				}
			}
		}
		
		// Show Console Command
		if (GetConVarInt(g_ChatConsole))
		{
			if(StrEqual(Cmd, "!console", false) || StrEqual(Cmd, "/console", false))
			{
				ClientCommand(client, "toggleconsole")
			}
		}
		
		// Overflow Command
		if (GetConVarInt(g_ChatOverflow))
		{
			if(StrEqual(Cmd, "!overflow", false) || StrEqual(Cmd, "/overflow", false))
			{
				ClientCommand(client, "retry")
			}
		}
		
		// Retry Command
		if (GetConVarInt(g_ChatRetry))
		{
			if(StrEqual(Cmd, "!retry", false) || StrEqual(Cmd, "/retry", false))
			{
				ClientCommand(client, "retry")
			}
		}
	}
	
	if (g_Check && Synergy)
	{
		// Teleplayer Command
		if (GetConVarInt(g_TelePlayer))
		{
			if(StrEqual(Cmd, "!saveme", false) || StrEqual(Cmd, "!save", false))
			{
				if (GetConVarInt(g_ChatHide))
					g_Return = true
			}
			if(StrEqual(Cmd, "!teleme", false))
			{
				if (GetConVarInt(g_ChatHide))
					g_Return = true
			}
		}
	}

	// There was a '/' in message?
	if (g_Return)
		return Plugin_Handled

	// If not then display the message
	return Plugin_Continue
}

//-------------------------------------------------//
// Set Stuck command to cheat for preventing abuse //
//-------------------------------------------------//
public mStuck(Handle:convar, const String:oldValue[], const String:newValue[])
{
	if (StringToInt(newValue) == 1)
	{
		new mflags = GetCommandFlags("stuck") // Get flags
		mflags &= ~FCVAR_CHEAT // add new flag "FCVAR_CHEAT" with '~'
		SetCommandFlags("stuck", mflags) // Set new flags
		PrintToServer("[SYN] Stuck ON") // message
	}
	else
	{
		new mflags = GetCommandFlags("stuck") // Get flags
		SetCommandFlags("stuck", mflags|FCVAR_CHEAT) // remove flag "FCVAR_CHEAT" with '|'
		PrintToServer("[SYN] Stuck OFF") // message
	}
}

//---------------------------------------------------//
// Set Explode command to cheat for preventing abuse //
//---------------------------------------------------//
public mExplode(Handle:convar, const String:oldValue[], const String:newValue[])
{
	if (StringToInt(newValue) == 1)
	{
		new mflags = GetCommandFlags("explode")
		mflags &= ~FCVAR_CHEAT
		SetCommandFlags("explode", mflags)
		PrintToServer("[SYN] Explode ON")
	}
	else
	{
		new mflags = GetCommandFlags("explode")
		SetCommandFlags("explode", mflags|FCVAR_CHEAT)
		PrintToServer("[SYN] Explode OFF")
	}
}

//------------------------------------------------//
// Set Kill command to cheat for preventing abuse //
//------------------------------------------------//
public mKill(Handle:convar, const String:oldValue[], const String:newValue[])
{
	if (StringToInt(newValue) == 1)
	{
		new mflags = GetCommandFlags("kill")
		mflags &= ~FCVAR_CHEAT
		SetCommandFlags("kill", mflags)
		PrintToServer("[SYN] Kill ON")
	}
	else
	{
		new mflags = GetCommandFlags("kill")
		SetCommandFlags("kill", mflags|FCVAR_CHEAT)
		PrintToServer("[SYN] Kill OFF")
	}
}